﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace MzkUi
{
    public partial class UiSong: UserControl
    {
        private int index = 0;
        private bool favorite = false;
        private bool start = false;
        public UiSong()
        {
            InitializeComponent();
        }
        // 添加一个布尔属性，命名为 "Favorite"，默认值为 false
        [Browsable(true), Category("MZK自定义"), Description("索引"), DefaultValue(false)]
        public int Index 
        {
            get { return index; }
            set { index = value; }
        }
        [Browsable(true), Category("MZK自定义"), Description("你是否喜爱当前歌曲？"), DefaultValue(false)]
        public bool Favorite
        {
            get  { return favorite; }
            set
            {
                favorite = value;
                if (value == true) // 3:不喜爱 2:喜爱
                    FavoriteMusicBtn.ImageIndex = 2;
                else
                    FavoriteMusicBtn.ImageIndex = 3;
            }
        }
        [Browsable(true), Category("MZK自定义"), Description("开始/暂停播放？"), DefaultValue(false)]
        public bool StartPlay
        {
            get { return start; }
            set
            {
                start = value;
                if (value == true) // true:开始 false:暂停
                    MusicStartBtn.ImageIndex = 0;
                else
                    MusicStartBtn.ImageIndex = 1;
                if (MusicStartBtn.ImageIndex == 0) // 0:播放 1:暂停
                {
                    MusicStartBtn.ImageIndex = 1;// 显示暂停按钮
                    NextMusicBtn.Visible = true;
                    PrevMusicBtn.Visible = true;
                }
                else
                {
                    MusicStartBtn.ImageIndex = 0;// 显示播放按钮
                    NextMusicBtn.Visible = false;
                    PrevMusicBtn.Visible = false;
                }
            }
        }

        [Browsable(true), Category("MZK自定义"), Description("返回Button，他们的名称为：FavoriteMusicBtn， PrevMusicBtn ，NextMusicBtn， MusicStartBtn")]
        public event EventHandler UiBtnClick;
        [Browsable(true), Category("MZK自定义"), Description("MusicLabel 被点击时触发")]
        public event EventHandler UiMusicBtn;

        private void UiSong_Load(object sender, EventArgs e)
        {
            if (favorite == true) // 3:不喜爱 2:喜爱
                FavoriteMusicBtn.ImageIndex = 2;
            else
                FavoriteMusicBtn.ImageIndex = 3;
            MusicStartBtn.ImageIndex =  0;

            // 添加提示
            UiSongTip.SetToolTip(FavoriteMusicBtn, "喜爱的");
            UiSongTip.SetToolTip(PrevMusicBtn, "上一首");
            UiSongTip.SetToolTip(NextMusicBtn, "下一首");
            UiSongTip.SetToolTip(MusicStartBtn, "开始/停止");
            UiSongTip.SetToolTip(MusicAuthor, "作者");
        }
        private void FavoriteMusicBtn_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.ImageIndex == 3) // 3:不喜爱 2:喜爱
            {
                btn.ImageIndex = 2;
                favorite = true;
            }
            else
            {
                btn.ImageIndex = 3;
                favorite = false;
            }
            // 触发公开的事件
            if (sender != null)
                UiBtnClick?.Invoke(sender, e);
        }

        private void StartMusicBtn_Click(object sender, EventArgs e)
        {
            if (MusicStartBtn.ImageIndex == 0) // 0:播放 1:暂停
            {
                MusicStartBtn.ImageIndex = 1;// 显示暂停按钮
                NextMusicBtn.Visible = true;
                PrevMusicBtn.Visible = true;
                start = true;
            }
            else
            {
                MusicStartBtn.ImageIndex = 0;// 显示播放按钮
                NextMusicBtn.Visible = false;
                PrevMusicBtn.Visible = false;
                start = false;
            }
            // 触发公开的事件
            if (sender != null)
                UiBtnClick?.Invoke(sender, e);
        }
        private void PrevMusicBtn_Click(object sender, EventArgs e)
        {
            // 触发公开的事件
            if (sender != null)
                UiBtnClick?.Invoke(sender, e);
        }
        private void NextMusicBtn_Click(object sender, EventArgs e)
        {
            // 触发公开的事件
            if (sender != null)
                UiBtnClick?.Invoke(sender, e);
        }

        private void Music_Click(object sender, EventArgs e)
        {
            // 触发公开的事件
            if (sender != null)
                UiMusicBtn?.Invoke(sender, e);
        }
    }
}
